package com.tbit.uqbike.client.remote;


/**
 * json返回的数据封装
 *
 * @author lmy
 * @date 2020/08/11 1:00
 */

public class CommonResult {


    private int code;


    private String message;


    private Object data;

    public CommonResult(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public CommonResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public CommonResult(int code) {
        this.code = code;
    }

    public CommonResult() {
    }

    /**
     * 成功的时候，返回 message 和 object
     *
     * @param message
     * @param object
     * @return
     */
    public static CommonResult success(String message, Object object) {
        return new CommonResult(200, message, object);
    }

    /**
     * 成功的时候，就返回 message 说明
     *
     * @param message
     * @return
     */
    public static CommonResult success(String message) {
        return new CommonResult(200, message);
    }

    /**
     * 成功的时候，不需要返回任何数据
     *
     * @return
     */
    public static CommonResult success() {
        return new CommonResult(200);
    }

    /**
     * 自定义返回状态码
     *
     * @param code
     * @param message
     * @return
     */
    public static CommonResult fail(int code, String message) {
        return new CommonResult(code, message);
    }

    /**
     * 自定义返回状态码
     *
     * @param code
     * @param message
     * @return
     */
    public static CommonResult failMessage(int code, String message, Object object) {
        return new CommonResult(code, message, object);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "CommonResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

}
